package com.ykzhujiang.lovespirit;

import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;

import com.ykzhujiang.lovespirit.analyzer.Analyzer;
import com.ykzhujiang.lovespirit.analyzer.TimeAnalyzer;
import com.ykzhujiang.lovespirit.labor.Labor;
import com.ykzhujiang.lovespirit.labor.TJULabor;
import com.ykzhujiang.lovespirit.parser.Parser;
import com.ykzhujiang.lovespirit.parser.TJUParser;
import com.ykzhujiang.lovespirit.util.ParserProcessor;

public class LoveSpirit {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
//		 SJTULabor l = new SJTULabor();
//		 Start(l, new SJTUParser(), new TimeAnalyzer(3600000 * 12));
		// Labor l = new SDULabor();
		// Start(l, new SDUParser(), new TimeAnalyzer(36000000l * 24l * 60l));
//		Labor l = new NanjingLabor();
//		Start(l, new NanjingParser(), new TimeAnalyzer(36000000l * 24l * 60l));
		Labor l = new TJULabor();
		Start(l, new TJUParser(), new TimeAnalyzer(36000000l * 24l * 60l));
	}

	public static void Start(Labor l, Parser p, Analyzer a) {
		l.Fetch(1);
		Document document = DocumentHelper.createDocument();
		Element root = document.addElement("threads");
		for (int i = 0; i < l.files.size(); i++) {
			ParserProcessor pp = new ParserProcessor(p, root, (String) l.files
					.get(i));
			pp.AddAnalyzer(a);
			Thread t;
			(t = new Thread(pp)).run();
			try {
				t.join();
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
}